package com.baomidou.springwind.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.springwind.entity.Employee;
import com.baomidou.springwind.mapper.EmployeeMapper;
import com.baomidou.springwind.service.IEmployeeService;
import com.baomidou.springwind.service.support.BaseServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2016/12/13.
 */
@Service
public class EmployeeServiceImpl extends BaseServiceImpl<EmployeeMapper, Employee>
        implements IEmployeeService {
    @Override
    public List<Employee> selectEmployeeById(String id) {
        List<Employee> employeeList = baseMapper.selectEmployeeById(id);
        return employeeList;
    }

    @Override
    public Page<Employee> selectAllEmployee(Page<Employee> page) {
        if (page.getTotal() == 0) {
            List<Employee> employeeList1 = baseMapper.selectList(null);
            page.setTotal(employeeList1.size());
        }
        List<Employee> employeeList = baseMapper.selectAllEmployee(page.getOffset(), page.getLimit());
        page.setRecords(employeeList);
        return page;
    }

    @Override
    public Page<Employee> selectByEmployeeNum(Page<Employee> page, String employeenum) {
        List<Employee> employeeList = baseMapper.selectByEmployeeNum(page.getOffset(), page.getLimit(), employeenum);
        page.setRecords(employeeList);
        return page;
    }

    @Override
    public Page<Employee> selectByEmployeeName(Page<Employee> page, String name) {
        List<Employee> employeeList = baseMapper.selectByEmployeeName(page.getOffset(), page.getLimit(), name);
        page.setRecords(employeeList);
        return page;
    }

    @Override
    public Page<Employee> selectByDepartmentName(Page<Employee> page, String name) {
        List<Employee> employeeList = baseMapper.selectByDepartmentName(page.getOffset(), page.getLimit(), name);
        page.setRecords(employeeList);
        return page;
    }


    public boolean upDateEmployeeById(Employee employee) {
        return baseMapper.upDateEmployeeById(employee);
    }

    @Override
    public int deleteEmployeeById(String id) {
        return baseMapper.deleteById(id);
    }


}
